
class Player extends imageClass{
    constructor(game){
        super(game, "player")
        this.game = game
        this.setup()
    }
    setup(){
        this.x = 150
        this.y = 400
        this.cooldown = config.fire_cooldown
    }
    moveLeft ()  {
        if (this.x >= 0){
            this.x -= this.speed
        }
    }
    moveRight (){
        if (this.x <= 500 - this.w){
            this.x += this.speed
        }
    }
    moveDown (){
        if (this.y <= 600 - this.h){
            this.y += this.speed
        }
    }
    moveUp (){
        if (this.y >= 0){
            this.y -= this.speed
        }
    }
    update(){
        this.speed = config.player_speed
        if (this.cooldown > 0){
            this.cooldown --
        }
    }
    fire(){
        if (this.cooldown == 0){
            this.cooldown = config.fire_cooldown
            var x = this.x + this.w/2 - 1
            var b = Bullet.new(this.game)
            b.x = x
            b.y = this.y - this.h
            this.scene.addArray(b, this.scene.bullet)
        }
    }
}